package com.xiaolun.controller;

import com.xiaolun.dao.UsersRepository;
import com.xiaolun.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author 硕鼠
 * @Date 2020/4/7 18:03
 * @Version 1.0
 * @Description 文件说明
 */
@Controller
public class TestController {

    @Autowired
    private UsersRepository usersRepository;

    @RequestMapping("/add")
    @ResponseBody
    public void saveTest(String name,int age) {
        Users users = new Users();
        users.setName(name);
        users.setAge(age);
        this.usersRepository.save(users);
    }

    // 查询全部用户
    @RequestMapping("/findUserAll")
    public String findUserAll(Model model) {
        List<Users> list = this.usersRepository.findAll();
        model.addAttribute("list", list);
        return "showUsers";
    }
}
